<?php
/**
 * Created by PhpStorm.
 * User: 69548
 * Date: 2018/8/27
 * Time: 15:14
 */

namespace app\admin\controller;


use think\Cookie;

class Channel extends User
{
    //列表展示
    public function index(){

     $data= model('Transferchannel')->paginate(20);


$this->assign('data',$data);

        return $this->fetch();
    }

    //新增
    public function add(){
        if (request()->post()){
          $name=  input('name');
         $da=  db('transferchannel')->insert([
               'name'=>$name,
               'creationtime'=>time(),
               'updatetime'=>time(),
               'admin_id'=>Cookie::get('admin'),

           ]);
         if ($da){
             return $this->success('添加成功');
         }else{
             return $this->error('添加失败');
         }

        }


return $this->fetch();

    }
    //修改
    public function edit(){

        if (request()->post()){
            $id=  input('channel_id');
//            $da=input('post');
//            dump($da);
            $name=  input('name');
            $da=  db('transferchannel')->where('channel_id',$id)->update([
                'name'=>$name,
//                'creationtime'=>time(),
                'updatetime'=>time(),
                'admin_id'=>Cookie::get('admin'),

            ]);
            if ($da){
                return $this->success('修改成功');
            }else{
                return $this->error('修改失败');
            }

        }
//        $da=input('post');
//            dump($da);
        $id=  input('id');

$d=db('transferchannel')->where('channel_id',$id)->find();
        $this->assign('d',$d);
        return $this->fetch();




    }
        //删除禁用
    public function del(){
      $id=  input('id');
      $state=  input('state');
        if ($state==0){
            $state=1;
        }else if ($state==1){
            $state=0;
        }
      $data=  db('transferchannel')->where('channel_id',$id)->update([
            'state'=>$state
        ]);

if ($data){
    return $this->success('操作成功');
}else{
    return $this->error('操作失败');
}


    }



}